import {
	APP_ENV
} from '@/utils/env.js'

function ajax(url, method, data, contentType) {
	return new Promise((resolve, reject) => {
		return uni.request({
			url: APP_ENV.VUE_APP_API_HOST + url,
			method,
			data,
			header: {
				'content-type': contentType || 'application/json'
			},
			success(res) {
				console.log(res)
				if (res.data.code) {
					resolve(res.data)
				} else {
					uni.showToast({
						title: res.data.message,
						icon: 'error',
						duration: 2000
					});
				}
			},
			fail(err) {
				reject(err)
			}
		})
	})
}
export {
	ajax
}
